//基本信息
var register_name_empty = "<div class='reg_style_link'><span>* 请填写您的用户名！</span></div>";
var register_name_length12 = "<div class='reg_style_link'><span>* 账号长度不超过7个汉字或14位之间( 数字、字母和下划线 ) 。</div>";
var register_password_empty = "<div class='reg_style_link'><span>* 密码不能为空。</span></div>";
var register_password_length = "<div class='reg_style_link'><span>* 密码长度必须在 6-16 个字符之间</span></div>";
var register_password2_empty = "<div class='reg_style_link'><span>* 请再输一次上面输入的密码</span></div>";
var register_password_compare = "<div class='reg_style_link'><span>* 两次密码不一致</span></div>";
var register_identity_card_empty = "<div class='reg_style_link'><span>* 请输入身份证号。</span></div>";
var register_company_address_empty = "<div class='reg_style_link'><span>* 请输入工作地址。</span></div>";
var register_name_exist = "<div class='reg_style_link'><span>* 手机号已存在</span></div>";
var register_email_empty = "<div class='reg_style_link'><span>* 电子邮箱不能为空</span></div>";
var register_email_exist = "<div class='reg_style_link'><span>* 该电子邮箱已经存在</span></div>";
var register_email_format = "<div class='reg_style_link'><span>* 该电子邮箱格式不正确</span></div>";
var register_email_right = "<div class='reg_style_link'><span>* 该电子邮箱可以正常使用</span></div>";
var register_email_checkformat = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$/;
var register_phone_right = "<div class='reg_style_link'><span>* 手机不能为空。</span></div>";
var register_password_right = "<div class='reg_style_links'><span>* 正确</span></div>";
var register_code_exist1 = "<div class='reg_style_link'><span>* 验证码不存在</span></div>";
var register_code_exist2 = "<div class='reg_style_link'><span>* 验证码已过期</span></div>";
var register_code_exist3 = "<div class='reg_style_links'><span>* 验证码可以使用</span></div>";
var register_code_empty = "<div class='reg_style_link'><span>* 验证码不能为空</span></div>";
var register_attribute_empty = "<div class='reg_style_link'><span>* 会员属性不能为空</span></div>";
var register_icon_empty = "<div class='reg_style_link'><span>* 头像不能为空</span></div>";
var registerlogin_name_length = "<div class='reg_style_link'><span>* 账号为4-20个字符</span></div>";
var register_login_name_format = "<div class='reg_style_link'><span>* 该登陆账号格式不正确</span></div>";
var register_phone_format = "<div class='reg_style_link'><span>*请填写正确的11位有效手机号</span></div>";
var register_login_name_checkformat = /^[\w]+$/; 
var register_phone_checkformat = /^1[3,5,8]\d{9}$/;
var register_name_length12 = "<div class='reg_style_link'><span>* 真实姓名不能多于8个字符</span></div>";
var register_names_empty = "<div class='reg_style_link'><span>* 请填写您的真实姓名</span></div>";
var register_nickname_empty = "<div class='reg_style_link'><span>* 登陆账号不能为空</span></div>";
var register_nickname_emptyss = "<div class='reg_style_link'><span>* 此账号已存在</span></div>";

var registerlogin_nickname_length = "<div class='reg_style_link'><span>* 昵称为4-20个字符</span></div>";

var name= false;
var phon=false;
var password=false;
//检测邮箱

function checkEmail(){
	var email = $('#email').val();
	var regErrorEmail = $('#emailTagDiv');
	/*验证电子邮箱是否为空
	if($('#email').val() == '') {
		$('#emailDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#emailTagDiv').addClass('register_tag_1');
	    $('#emailTagDiv').html("<span class='message_span'>"+register_email_empty+"</span>");
		return false;
	} else 
	*/
	if($('#email').val() == '') {
		return true;
	}
	if(!register_email_checkformat.test($('#email').val())){
		$('#emailDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#emailTagDiv').addClass('register_tag_1');
	    $('#emailTagDiv').html("<span class='message_span'>"+register_email_format+"</span>");
		return false;
	} else {
		$('#emailDiv').addClass("register_mainBox_row_a_input_input_01");
		$("#emailTagDiv").addClass('register_tag_3');
		$("#emailTagDiv").html("<span class=register_tag_3_span>"+register_password_right+"</span>");
		}
}

//检测用户名
function checkUserName(){
	if($('#username').val() == '') {
		$('#nameDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#nameTagDiv').addClass("register_tag_1");
	    $('#nameTagDiv').html("<span class='message_span'>"+register_name_empty+"</span>");
		return false;
	}else if($('#username').val().length > 20 || $('#username').val().length < 4){
		$('#nameDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#nameTagDiv').addClass("register_tag_1");
	    $('#nameTagDiv').html("<span class='message_span'>"+registerlogin_name_length+"</span>");
		return false;
	} else if(!register_login_name_checkformat.test($('#username').val())){
		$('#nameDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#nameTagDiv').addClass('register_tag_3');
		$('#nameTagDiv').html("<span class=register_tag_3_span>"+register_login_name_format+"</span>");
		return false;
	} else {
		if($('#username').val() != ""){
			$.post('index.php?p=register&a=checks',{
				username:$('#username').val(),
				regname:"regusername"
			},
			function (data) {	//回传函数
				if(data == 1){
					$('#nameDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#nameTagDiv").addClass('register_tag_1');
					$("#nameTagDiv").html("<span class='message_span'>"+register_name_exist+"</span>");
				} else {
					$('#nameDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#nameTagDiv").addClass('register_tag_3');
					$("#nameTagDiv").html("<span class=register_tag_3_span>"+register_password_right+"</span>");
				}
				$("#nameTagDiv").show();
			});
		}
	}
}
//nickname

function checknicknameName(){
	if($('#nickname').val() == '') {
		$('#nicknameDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#nicknameTagDiv').addClass("register_tag_1");
	    $('#nicknameTagDiv').html("<span class='message_span'>"+register_nickname_empty+"</span>");
		name = false;
	} else if($('#nickname').val().length < 4 || $('#nickname').val().length > 20) {
			$('#nicknameDiv').addClass("register_mainBox_row_a_input_input_01");
			$('#nicknameTagDiv').addClass("register_tag_1");
			$('#nicknameTagDiv').html("<span class='message_span'>"+registerlogin_name_length+"</span>");
		name = false;
		
	}else{
			$('#nicknameDiv').addClass("register_mainBox_row_a_input_input_01");
			$("#nicknameTagDiv").addClass('register_tag_3');
			$("#nicknameTagDiv").html("<span class=register_tag_3_span>"+register_password_right+"</span>");
					name = true;
	
	}
		if($('#nickname').val() != ""){
			$.post('index.php?p=register&a=checkss',{
				nickname:$('#nickname').val()
			},
			function (data) {	//回传函数
				if(data == 1){
					$('#nicknameDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#nicknameTagDiv").addClass('register_tag_1');
					$("#nicknameTagDiv").html("<span class='message_span'>"+register_nickname_emptyss+"</span>");
					name = false;
				} else {
					$('#nicknameDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#nicknameTagDiv").addClass('register_tag_3');
					$("#nicknameTagDiv").html("<span class=register_tag_3_span>"+register_password_right+"</span>");
					name = true;
				}
			});
		}
}
//检测密码1
function checkPassword(){
	if($('#reg_passwd').val() == '') {
		$('#passWordDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#passWordTagDiv').addClass('register_tag_1');
	    $('#passWordTagDiv').html("<span class='message_span'>"+register_password_empty+"</span>");
		password = false;
	} else if($('#reg_passwd').val().length < 6 || $('#reg_passwd').val().length > 16){
		$('#passWordDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#passWordTagDiv').addClass('register_tag_1');
	    $('#passWordTagDiv').html("<span class='message_span'>"+register_password_length+"</span>");
		password = false;
	} else {
		$('#passWordDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#passWordTagDiv').addClass('register_tag_3');
		$('#passWordTagDiv').html("<span class=register_tag_3_span>"+register_password_right+"</span>");
		password = true;
	}
}
/*
//检测密码2
function checkPassword2(){
	if($('#reg_passwd2').val() == '') {
		$('#repassWordDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#rePassWordTagDiv').addClass('register_tag_1');
	    $('#rePassWordTagDiv').html("<span class='message_span'>"+register_password2_empty+"</span>");
		password2 = false;
	} else if (($('#reg_passwd').val() != '') || ($('#reg_passwd2').val() != '')) {
		if($('#reg_passwd').val() != $('#reg_passwd2').val()){
			$('#repassWordDiv').addClass("register_mainBox_row_a_input_input_01");
			$('#rePassWordTagDiv').addClass('register_tag_1');
	  		$('#rePassWordTagDiv').html("<span class='message_span'>"+register_password_compare+"</span>");
			password2 = false;
		} else {
			$('#repassWordDiv').addClass("register_mainBox_row_a_input_input_01");
			$('#rePassWordTagDiv').addClass('register_tag_3');
	  		$('#rePassWordTagDiv').html("<span class='message_span'>"+register_password_right+"</span>");
			password2 = true;
		}
	} else {
		$('#repassWordDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#rePassWordTagDiv').addClas('register_tag_3');
		$('#rePassWordTagDiv').html("<span class=register_tag_3_span>"+register_password_right+"</span>");
		password2 = true;
	}
}
*/
//检测移动电话
function checkMobile_phone(){

	if($('#mobile_phone').val() == '') {
		$('#mobile_phoneDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#mobile_phoneTagDiv').addClass("register_tag_1");
	    $('#mobile_phoneTagDiv').html("<span class='message_span'>"+register_phone_right+"</span>");
	} else if(!register_phone_checkformat.test($('#mobile_phone').val())){
		$('#mobile_phoneDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#mobile_phoneTagDiv').addClass('register_tag_3');
		$('#mobile_phoneTagDiv').html("<span class=register_tag_3_span>"+register_phone_format+"</span>");
	} else {	
		if($('#mobile_phone').val() != ""){
			$.post('index.php?p=register&a=checks',{
				mobile_phone:$('#mobile_phone').val()
			},
			function (data) {	//回传函数
				if(data == 1){
					$('#mobile_phoneDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#mobile_phoneTagDiv").addClass('register_tag_1');
					$("#mobile_phoneTagDiv").html("<span class='message_span'>"+register_name_exist+"</span>");
					phon = false;
				} else {
					$('#mobile_phoneDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#mobile_phoneTagDiv").addClass('register_tag_3');
					$("#mobile_phoneTagDiv").html("<span class=register_tag_3_span>"+register_password_right+"</span>");
					phon = true;
				}
				$("#mobile_phoneTagDiv").show();
			});
		}
	}
}
//提交注册基本信息
function submitReigister(){
	if(name&&phon&&password){
		showPop('reg_suc_pop',400);
		
	    $.post('index.php?p=register&a=regsave',{
		
		name:$('#name').val(),
		nickname:$('#nickname').val(),
		reg_passwd:$('#reg_passwd').val(),
		reg_passwd2:$('#reg_passwd2').val(),
		mobile_phone:$('#mobile_phone').val(),
		//address:$('#address').val(),
		email:$('#email').val(),
		sex:$("input[name='sex']:checked").val(),
		address:$("input[name='address']:checked").val(),
		user_type:$("input[name='user_type']:checked").val()
			
		},
		function (data) {	//回传函数
			 showPop('reg_suc_pop',400);
		//	alert(data);
			
			if(trim(data).length > 20){
				var msgs = data.split("!!");
				for(var i=0;i<msgs.length;i++){
					var submsg = msgs[i].split("##");
					var msgDiv = trim(submsg[0]);
					warning($("#"+msgDiv),submsg[1]);
				}
				cancelPop('reg_suc_pop');
			}
			
			if(data==""){
				window.location.href="index.php?p=user&a=register";
				return false;
			}
			
			if(data=="用户信息错"){
				alert(data);
				return false;
			}else
			if(data=="手机号码格式不正确"){
				alert(data);
				return false;
			}else if(data=="请求参数错误"){
				alert(data);
				return false;
			}else if(data=="000"){
				alert('选择地区');
				window.location.href="index.php?p=user&a=register";
				return false;
			}else if(data=="余额不足"){
				alert(data);
				return false;
			}else if(data=="发送失败"){
				alert(data);
				return false;
			}else if(data=="其他错误"){
				alert('错误812');
				return false;
			}else if(data=="发送成功"){
				window.location.href="index.php?p=register&a=reg2";
			} 	
			
			//else{
			//	window.setTimeout("reloadyemian();",500);
			//}
		});
	
	}else{
		alert('填写资料不完善')
	}
}
function reloadyemian(){ 
	window.location.href="index.php?p=register&a=reg2";
}

function warning(obj, msg) {
	obj.addClass('register_tag_1');
	obj.show();
	obj.html("<span class='reg_style_link'>"+msg+"</span>");
}
function trim(str) {
	return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1'); 
}


//check验证码
function checkCode(){
	if($('#reg_vCode_input').val() == '') {
		$('#codeDiv').addClass("register_mainBox_row_a_input_input_01");
		$('#reg_vCode_inputTagDiv').addClass("register_tag_1");
	    $('#reg_vCode_inputTagDiv').html("<span class='message_span'>"+register_code_empty+"</span>");
		return false;
	}else{
		if($("#reg_vCode_input").val() !=""){
			$.post('index.php?p=register&a=check',{
				validateCode:$("#reg_vCode_input").val()
			},
			function (data) {	//回传函数
				if(data == 1){
					$('#codeDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#reg_vCode_inputTagDiv").addClass('register_tag_1');
					$("#reg_vCode_inputTagDiv").html("<span class='message_span'>"+register_code_exist1+"</span>");
				}if(data == 2){
					$('#codeDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#reg_vCode_inputTagDiv").addClass('register_tag_1');
					$("#reg_vCode_inputTagDiv").html("<span class='message_span'>"+register_code_exist2+"</span>");
				}if(data == 3){
					$('#codeDiv').addClass("register_mainBox_row_a_input_input_01");
					$("#reg_vCode_inputTagDiv").addClass('register_tag_1');
					$("#reg_vCode_inputTagDiv").html("<span class='message_span'>"+register_code_exist3+"</span>");
				}
			});	
		}
	}
}
//换注册码
function reloadcode(){
	//更换验证码图片
	$('#reg_vCode').attr('src','images/checkNum_session.php?imag='+Math.random());
}